<template>
  <div class="zhengti">
    <!--搜索条件-->
    <div class="boxone">
      <el-form :inline="true">

        <el-form-item label="时间:" label-width="50px">
          <el-date-picker
            v-model="startTime"
            style="width:70%"
            type="date"
            placeholder="起始日期">
          </el-date-picker>
        </el-form-item>

        <el-form-item label="~" label-width="50px" style="margin-left: -5.5%">
          <el-date-picker
            v-model="endTime"
            style="width:70%"
            type="date"
            placeholder="结束日期">
          </el-date-picker>
        </el-form-item>

        <el-form-item label="统计类别：" label-width="100px" style="margin-left:-3%">
          <el-select v-model="tableVisable" placeholder="请选择" style="width:70%">
            <el-option
              v-for="item in searchTypeSelection"
              style="width:70%"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="卡号:" label-width="50px" style="margin-left: -3%">
          <el-input v-model="queryParams.cardNumber" placeholder="请输入内容" style="width:80%"></el-input>
        </el-form-item>

        <el-form-item label="售卡人:" label-width="60px" style="margin-left: -1.5%">
          <el-input v-model="queryParams.cardSeller" placeholder="请输入内容" style="width:70%"></el-input>
        </el-form-item>

        <!--<el-form-item label="付款方式：" label-width="100px" style="margin-left: -4%">-->
        <!--  <el-select v-model="value8" placeholder="请选择" style="width:70%">-->
        <!--    <el-option-->
        <!--      v-for="item in options6"-->
        <!--      style="width:70%"-->
        <!--      :key="item.value"-->
        <!--      :label="item.label"-->
        <!--      :value="item.value">-->
        <!--    </el-option>-->
        <!--  </el-select>-->
        <!--</el-form-item>-->

        <el-form-item label="卡性质：" label-width="100px" style="margin-left: -4%">
          <el-select v-model="queryParams.cardNature" placeholder="请选择" style="width:70%">
            <el-option
              v-for="dict in dict.type.yqg_card_nature"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value">
            </el-option>
          </el-select>
        </el-form-item>
        <!--</el-form>-->

        <!--<el-form>-->
        <el-form-item style="float:right">
          <el-button type="primary" size="small" @click="handleSearch">搜索</el-button>
          <el-button size="small" @click="reset">重置</el-button>
          <el-button type="success" size="small" @click="handleExport">导出</el-button>
        </el-form-item>
      </el-form>
    </div>

    <!--开户续款表格-->
    <div class="biao" v-show="tableVisable==='0'">
      <el-table :data="tableDataOpen" border :loading="loading" height="650" style="width: 100%" empty-text="玉泉宫">

        <el-table-column align="center" prop="id" label="序号" width="80px"/>

        <el-table-column align="center" prop="cardNumber" label="卡号"/>

        <el-table-column align="center" prop="memberCounterNumber" label="会员柜号"/>

        <el-table-column align="center" prop="type" label="类型" width="120">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.yqg_type" :value="scope.row.type"/>
          </template>
        </el-table-column>

        <el-table-column align="center" prop="cardNature" label="卡性质">
          <template slot-scope="scope">
            <div v-if="scope.row.cardNature==='990'">小计</div>
            <div v-else-if="scope.row.cardNature==='991'">收款总计</div>
            <div v-else-if="scope.row.cardNature==='992'">现金</div>
            <div v-else-if="scope.row.cardNature==='993'">银行卡</div>
            <div v-else-if="scope.row.cardNature==='994'">办卡总计</div>
            <div v-else-if="scope.row.cardNature==='995'">续款总计</div>
            <dict-tag :options="dict.type.yqg_card_nature" :value="scope.row.cardNature" v-else/>
          </template>
        </el-table-column>

        <el-table-column align="center" prop="name" label="姓名"/>

        <el-table-column align="center" prop="giftCardSign" label="赠送"/>

        <el-table-column align="center" prop="actualAmount" label="存款金额"/>

        <el-table-column align="center" prop="consumptionValue" label="消费金额"/>

        <el-table-column align="center" prop="checkoutMethod" label="结账方式"/>

        <el-table-column align="center" prop="residualAmount" label="卡余额"/>

        <el-table-column align="center" prop="accountOpeningTime" label="交易时间"/>

      </el-table>
    </div>

    <!--销户表格-->
    <div class="biao" v-show="tableVisable==='1'">
      <el-table :data="tableDataDel" :loading="loading" border height="650" style="width: 100%" empty-text="玉泉宫">

        <el-table-column align="center" prop="id" label="序号" width="80px"/>

        <el-table-column align="center" prop="cardNumber" label="卡号"/>

        <el-table-column align="center" prop="memberCounterNumber" label="会员柜号"/>

        <el-table-column align="center" prop="name" label="持卡人姓名"/>

        <el-table-column align="center" prop="type" label="类型" width="120">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.yqg_type" :value="scope.row.type"/>
          </template>
        </el-table-column>

        <el-table-column align="center" prop="cardNature" label="卡性质">
          <template slot-scope="scope">
            <div v-if="scope.row.cardNature==='991'">储值卡小计</div>
            <div v-else-if="scope.row.cardNature==='992'">次卡总计</div>
            <div v-else-if="scope.row.cardNature==='993'">总计</div>
            <dict-tag :options="dict.type.yqg_card_nature" :value="scope.row.cardNature" v-else/>
          </template>
        </el-table-column>

        <el-table-column align="center" prop="residualAmount" label="剩余金额"/>

        <el-table-column align="center" prop="operator" label="经手人"/>

        <el-table-column align="center" prop="accountClosureTime" label="销户时间"/>

      </el-table>
    </div>
  </div>
</template>

<script>
import {open, delA} from "@/api/module/wtc/form.js"

export default {
  dicts: ['yqg_card_nature', 'yqg_type'],
  data() {
    return {
      /*起始日期选择器*/
      startTime: '',
      endTime: '',
      searchTypeSelection: [
        {
          value: '0',
          label: '开户续款'
        }, {
          value: '1',
          label: '销户'
        }
      ],
      value8: '',
      options6: [
        {
          value: '选项1',
          label: '全部'
        }, {
          value: '选项2',
          label: '方式1'
        }, {
          value: '选项3',
          label: '方式2'
        }
      ],
      // 会员表查询参数
      queryParams: {
        cardNumber: null,
        name: null,
        consumptionValue: null,
        accumulatedConsumption: null,
        residualAmount: null,
        residualIntegral: null,
        type: null,
        cardNature: null,
        actualAmount: null,
        depositConsumption: null,
        netBalance: null,
        cancellationDate: null,
        dateUse: null,
        dateBirth: null,
        discountRate: null,
        numberRenewals: null,
        cardStatus: null,
        masterCardNumber: null,
        sex: null,
        giftCardSign: null,
        cardSeller: null,
        password: null,
        redeemPoints: null,
        cumulativeIntegral: null,
        memberCounterNumber: null,
        accountOpeningTime: null,
        discountScheme: null,
        effectiveDate: null,
        idCard: null,
        mobilePhone: null,
        homePhone: null,
        workUnit: null,
        address: null,
        note: null,
        preferentialScheme: null,
        note1: null,
        note2: null,
        note3: null,
        note4: null,
        note5: null,
        note6: null,
        note7: null,
        note8: null,
        note9: null,
        note10: null
      },
      tableVisable: '0',
      loading: false,
      tableDataOpen: [],
      tableDataDel: []
    }
  },

  methods: {
    handleSearch() {
      if (this.startTime === '' || this.endTime === '' || this.startTime === null || this.endTime === null) {
        return
      }
      this.tableDataOpen = []
      this.tableDataDel = []
      this.loading = true
      if (this.tableVisable === '0') {
        open(this.startTime, this.endTime, this.queryParams.cardNumber, this.queryParams.cardSeller, this.queryParams.cardNature).then(res => {
          this.tableDataOpen = res.rows
          this.loading = false
        })
      } else if (this.tableVisable === '1') {
        delA(this.startTime, this.endTime, this.queryParams.cardNumber, this.queryParams.cardSeller, this.queryParams.cardNature).then(res => {
          this.tableDataDel = res.rows
          this.loading = false
        })
      }
    },
    reset() {
      this.startTime = ''
      this.endTime = ''
      this.queryParams = {
        cardNumber: null,
        name: null,
        consumptionValue: null,
        accumulatedConsumption: null,
        residualAmount: null,
        residualIntegral: null,
        type: null,
        cardNature: null,
        actualAmount: null,
        depositConsumption: null,
        netBalance: null,
        cancellationDate: null,
        dateUse: null,
        dateBirth: null,
        discountRate: null,
        numberRenewals: null,
        cardStatus: null,
        masterCardNumber: null,
        sex: null,
        giftCardSign: null,
        cardSeller: null,
        password: null,
        redeemPoints: null,
        cumulativeIntegral: null,
        memberCounterNumber: null,
        accountOpeningTime: null,
        discountScheme: null,
        effectiveDate: null,
        idCard: null,
        mobilePhone: null,
        homePhone: null,
        workUnit: null,
        address: null,
        note: null,
        preferentialScheme: null,
        note1: null,
        note2: null,
        note3: null,
        note4: null,
        note5: null,
        note6: null,
        note7: null,
        note8: null,
        note9: null,
        note10: null
      }
      this.tableDataOpen = []
      this.tableDataDel = []
    },
    handleExport() {
      if (this.startTime === '' || this.endTime === '' || this.startTime === null || this.endTime === null) {
        return
      }
      let stime = new Date(this.startTime).getTime()
      let etime = new Date(this.endTime).getTime()
      this.queryParams.note1 = stime
      this.queryParams.note2 = etime
      if (this.tableVisable === '0') {
        this.download('project/wtc/form/export/open', {
          ...this.queryParams
        }, `会员卡开户续款表_${new Date().getTime()}.xlsx`)
      } else if (this.tableVisable === '1') {
        this.download('project/wtc/form/export/del', {
          ...this.queryParams
        }, `会员卡销户表_${new Date().getTime()}.xlsx`)
      }
    }
  }
}
</script>

<style scoped>
.zhengti {
  display: flex;
  flex-direction: column;
  margin-left: 1%;
  margin-right: 1%;
  margin-bottom: 1%;
}

.boxone {
  margin-top: 2%;
  display: inline-block;
}

.biao {
  margin-top: 5px;
}
</style>
